package com.example.arithmeticleetcode.leetcode.october;

import java.util.Arrays;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-28 10:02
 **/
public class Demo18 {

    public static void main(String[] args) {
        System.out.println(balancedStringSplit("RLRRLLRLRL"));
    }

    public static int balancedStringSplit(String s) {
        int num = 0;
        int n = 0;
        for (int i = 0, len = s.length(); i < len; i++) {
            if (s.charAt(i) == 'R') {
                n ++;
            }
            if (s.charAt(i) == 'L') {
                n --;
            }
            if (n == 0) {
                num ++;
            }
        }
        return num;
    }
}
